package com.yyplatform.admin.platform.notice.controller;

import static com.yyplatform.admin.Constants.URL_PREFIX;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yyplatform.admin.infra.model.RestResponse;
import com.yyplatform.admin.platform.notice.model.dto.SysNoticeDTO;
import com.yyplatform.admin.platform.notice.model.dto.SysNoticeFormDTO;
import com.yyplatform.admin.platform.notice.model.dto.SysNoticeQueryDTO;
import com.yyplatform.admin.platform.notice.service.SysNoticeService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author sleepforests@163.com
 * <p>
 * Created on 2024/9/24 22:50
 */
@Slf4j
@Tag(name = "通知/站内通知管理")
@AllArgsConstructor
@RestController
@RequestMapping(URL_PREFIX + "/sys/notice/")
public class SysNoticeController {

    private SysNoticeService sysNoticeService;


    @GetMapping("query")
    @Operation(summary = "查询")
    @RequiresPermissions("sys:notice:query")
    public RestResponse<Page<SysNoticeDTO>> page(SysNoticeQueryDTO queryDTO) {
        log.debug("query dto = {}", queryDTO);


        Page<SysNoticeDTO> page = sysNoticeService.query(queryDTO);

        return RestResponse.ok(page);
    }


    @GetMapping("get")
    @Operation(summary = "通过ID获取详情")
    @RequiresPermissions("sys:notice:get")
    public RestResponse<SysNoticeDTO> get(Long id) {
        log.debug("get by id is {}", id);

        SysNoticeDTO data = sysNoticeService.get(id);
        return RestResponse.ok(data);
    }


    @PostMapping("save")
    @Operation(summary = "保存")
    @RequiresPermissions("sys:notice:save")
    public RestResponse<Void> save(@RequestBody SysNoticeFormDTO sysDeptFormDTO) {
        log.debug("save dto is {}", sysDeptFormDTO);

        sysNoticeService.save(sysDeptFormDTO);

        return RestResponse.ok(null);
    }


    @PostMapping("update")
    @Operation(summary = "修改")
    @RequiresPermissions("sys:notice:update")
    public RestResponse<Void> update(@RequestBody SysNoticeFormDTO sysDeptFormDTO) {
        log.debug("update dto is {}", sysDeptFormDTO);
        sysNoticeService.update(sysDeptFormDTO);
        return RestResponse.ok(null);
    }


    @PostMapping("send")
    @Operation(summary = "通知发送")
    @RequiresPermissions("sys:notice:send")
    public RestResponse<Void> send(Long id) {
        log.debug("send by id is {}", id);

        sysNoticeService.send(id);
        return RestResponse.ok(null);
    }

    @PostMapping("delete")
    @Operation(summary = "删除")
    @RequiresPermissions("sys:notice:delete")
    public RestResponse<Void> delete(Long id) {
        log.debug("delete by id is {}", id);

        sysNoticeService.delete(id);
        return RestResponse.ok(null);
    }

}
